package org.linlinjava.litemall.app.config;

import org.linlinjava.litemall.app.annotation.support.LoginUserHandlerMethodArgumentResolver;
import org.linlinjava.litemall.app.interceptor.AuthHandlerInterceptor;
import org.linlinjava.litemall.app.interceptor.MchHandlerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class AppWebMvcConfiguration implements WebMvcConfigurer {

    @Bean
    MchHandlerInterceptor mchHandlerInterceptor(){
        return new MchHandlerInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> authPatterns=new ArrayList<>();
        authPatterns.add("/app/auth/**");
        registry.addInterceptor(new AuthHandlerInterceptor()).excludePathPatterns(authPatterns);

        registry.addInterceptor(mchHandlerInterceptor()).addPathPatterns("/app/gamch/**");
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(new LoginUserHandlerMethodArgumentResolver());
    }



}
